package cn.ljlao.mallsearch.controller;

import cn.ljlao.common.dto.es.SkuEsModel;
import cn.ljlao.common.exception.MallResponseCode;
import cn.ljlao.common.utils.R;
import cn.ljlao.mallsearch.service.ProductSaveService;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

/**
 * @Author: LiuZhen
 * @Created: 2021/8/1 22:19
 * @Description:
 */
@RestController
@RequestMapping("/search")
@Slf4j
public class ElasticSaveController {

    @Autowired
    private ProductSaveService productSaveService;

    //上架商品
    @PostMapping("/product")
    public R productSaveUp(@RequestBody List<SkuEsModel> skuEsModels)  {
        Boolean b = false;
        try {
            b = productSaveService.productStatusUp(skuEsModels);
        } catch (IOException e) {
            log.error("商品上架出错");
            return R.error(MallResponseCode.PRODUCT_UP_EXCEPTION.getRspCode(),MallResponseCode.PRODUCT_UP_EXCEPTION.getMsg());
        }
        if (!b){
            return R.ok();
        }
        return R.error(MallResponseCode.PRODUCT_UP_EXCEPTION.getRspCode(),MallResponseCode.PRODUCT_UP_EXCEPTION.getMsg());


    }

}
